<template>
	<view class="configuration">
		<view class="top-box">
			<el-breadcrumb separator="/">
				<el-breadcrumb-item>数据收益</el-breadcrumb-item>
				<el-breadcrumb-item>{{ getBreadcrumb }}</el-breadcrumb-item>
			</el-breadcrumb>
			
			<view class="header-serch flex ac jcsb">
				<!-- 媒体数据 or 广告位数据 -->
				<view class="search-box flex ac">
					<view class="search flex ac">
						<view class="search-title min-w72" :class="{ 'min-w86': second }">{{ second? '广告位':'媒体' }}名称：</view>
						<el-input v-model="name" :placeholder="second? '请输入广告位名称':'请输入媒体名称'" style="height: 32px;"></el-input>
					</view>
					<view class="search flex ac">
						<view class="search-title min-w86">渠道：</view>
						<el-select v-model="value" placeholder="请选择渠道">
							<el-option
							  v-for="t in selectArr"
							  :key="t.value"
							  :label="t.label"
							  :value="t.value">
							</el-option>
						</el-select>
					</view>
					<view></view>
					<view class="search-btn">
						<el-button type="primary" class="search-button" @click='search'>查询</el-button>
					</view>
				</view>
				
				<el-button class="add-user" type="primary" @click='openDelog'>数据上传</el-button>
			</view>
			
			<el-table 
				:data="Table.TableDataList" 
				style="width: 100%;" 
				height="calc(100vh - 298px)"
				stripe
				:header-cell-style="{background:'#E9ECEE',color:'#16171F'}">
				<el-table-column 
					show-overflow-tooltip 
					:prop="item.prop" 
					:label="item.label" 
					v-for="(item,index) in newTitleList"
					:key="index">
					<template slot-scope="scope">
						<!-- 每一项的值 -->
						<span v-if="item.prop && item.prop != 'channel'">{{ (item.prop == 'createDate' || item.prop == 'mepDate')? new Date(scope.row[item.prop]).format():scope.row[item.prop] }}</span>
						
						<span v-if="item.prop && item.prop == 'channel'">{{ scope.row[item.prop] || '其他' }}</span>
						<!-- 操作项 -->
					</template>
				</el-table-column>
			</el-table>
		</view>
		<view class="footer">
			<el-pagination  
				@size-change="handleSizeChange" 
				@current-change="handleCurrentChange"
				:current-page="Table.page"  
				layout="total, prev, pager, next, jumper, sizes" 
				background 
				:total="Table.count"
				:page-sizes="[10, 12]" 
				:page-size.sync="Table.limit">
			</el-pagination>
			<view class="pageLimit">当前显示{{Table.limit}}条/页</view>
		</view>
		
		<confirm @confirmFlagClick="confirmFlagClick" :confirmFlag="confirmFlag" :title="confirmTitle"></confirm>
		<dataRevenueDialog :dialogVisible="addUserDialogFlag" @closeDialog="closeDialog" :item="currentUpdate" :title="addDialogTitle" :second="second"></dataRevenueDialog>
	</view>
</template>

<script>
	import { Request } from '../model/request.js'
	import { Util } from '../utils/util.js'
	import confirm from './dialog/confirm.vue'
	import dataRevenueDialog from './dialog/dataRevenueDialog.vue'
	 
	export default {
		components: { confirm, dataRevenueDialog },
		
		props: {
			second: {
				type: [String, Number],
				default: 0
			}
		},
		
		computed: {
			getBreadcrumb() {
				let c = '媒体数据'
				if (this.second == 1) {
					c = '广告位数据'
				}
				return c
			},
			
			newTitleList() {
				if (this.second == 1) {
					return this.Table.titleList1
				}else {
					return this.Table.titleList
				}
			}
		},
		
		data() {
			return {
				phone: '',
				name: '',
				selectArr: [
					{
					  value: '',
					  label: '全部'
					}, {
					  value: '推啊',
					  label: '推啊'
					}, {
					  value: '变现猫',
					  label: '变现猫'
					}
				],
				value: '',
				Table: {
					titleList: [{
							prop: "mediaName",
							label: "媒体名称"
						},
						{
							prop: "mediaSp",
							label: "系统平台"
						},
						{
							prop: "mepDate",
							label: "收益时间"
						},
						{
							prop: "mepExposure",
							label: "曝光量"
						},
						{
							prop: "mepCr",
							label: "点击量"
						},
						{
							prop: "mepCtr",
							label: "点击率"
						},
						{
							prop: "mepPv",
							label: "广告访问pv"
						},
						{
							prop: "mepUv",
							label: "广告访问UV"
						},
						// {
						// 	prop: "uvEarnings",
						// 	label: "每日收益"
						// },
						{
							prop: "mepAi",
							label: "预计收益"
						},
						{
							prop: "channel",
							label: "渠道"
						}
					],
					titleList1: [{
							prop: "adName",
							label: "广告位名称"
						},
						// {
						// 	prop: "specification",
						// 	label: "广告规格"
						// },
						{
							prop: "createDate",
							label: "收益时间"
						},
						{
							prop: "exposure",
							label: "曝光量"
						},
						{
							prop: "hits",
							label: "点击量"
						},
						// {
						// 	prop: "clickRate",
						// 	label: "点击率"
						// },
						{
							prop: "visitPv",
							label: "广告访问pv"
						},
						{
							prop: "visitUv",
							label: "广告访问UV"
						},
						// {
						// 	prop: "uvEarnings",
						// 	label: "每日收益"
						// },
						{
							prop: "predictEarnings",
							label: "预计收益"
						},
						{
							prop: "channel",
							label: "渠道"
						}
					],
					TableDataList: [],
					result: '',
					page: 1,
					limit: 10,
					count: 0
				},
				
				confirmFlag: false,
				confirmTitle: '',
				confirmType: '',
				currentDelItem: {},
				
				addUserDialogFlag: false,
				addDialogTitle: '',
				currentUpdate: {},
			}
		},
		
		mounted() {
			this.initTable()
		},
		
		watch: {
			second(newVal, oldVal) {
				this.phone = ''
				this.name = ''
				this.value = this.value2 = this.value3 = ''
				this.Table.page = 1
				this.Table.limit = 10
				this.Table.count = 0
				this.initTable()
			},
			value() {
				this.initTable()
			}
		},
		
		methods: {
			getMediaStatus(i) {
				if (i == 1) {
					return '不可用'
				} else if (i == 2) {
					return '待审核'
				} else if (i == 3) {
					return '审核拒绝'
				} else {
					return '可用'
				}
			},
			
			search() {
				console.log()
				this.initTable()
			},
			
			async initTable(page) {
				this.Table.TableDataList = []
				if (!Util.isNull(page)) {
					this.Table.page = page
				} else {
					this.Table.page = 1
				}
				let res
				if (this.second == 1) { // 广告位数据
					res = await Request.PARTFINDALL(this.Table.page, this.Table.limit, this.name, this.value)
				} else { // 媒体数据
					res = await Request.MEPFINDALL(this.Table.page, this.Table.limit, this.name, this.value)
				}
				console.log(res, 'resswss')
				if (!Util.isNull(res)) {
					this.Table.TableDataList = res.data.records
					this.Table.count = res.data.total
				} else {
					this.Table.TableDataList = null
				}
			},
			
			openDelog() {
				if (this.second) {
					this.addDialogTitle = '广告位数据上传'
				} else {
					this.addDialogTitle = '媒体数据上传'
				}
				this.addUserDialogFlag = true
			},
			
			closeDialog(flag) {
				this.currentUpdate = {}
				this.addUserDialogFlag = false
				if (typeof flag != 'function' && flag) {
					this.initTable()
				}
			},
			
			// 确认框触发事件
			confirmFlagClick(i) {
				if (i) { // 确认
					if (!this.second) { // 媒体审核
						console.log('媒体审核，确认了')
					} else if (this.second == 1) { // 广告位审核
						console.log('广告位，确认了')
					} else { // 广告链接
						
					}
				}
				this.confirmFlag = false
			},
			
			handleSizeChange(val) {
				console.log(`每页 ${val} 条`);
				this.initTable()
			},
			
			handleCurrentChange(val) {
				console.log(`当前页: ${val}`);
				this.initTable(val)
			}
		}
	}
</script>

<style scoped>
	.configuration {
		/* padding: 20px 40px 50px; */
		position: relative;
	}
	
	.top-box {
		padding: 20px 40px 0;
	}
	
	.header-serch {
		margin: 30px 0;
	}
	
	.search-title {
		/* width: 100px; */
		font-size: 14px;
		font-weight: 500;
		color: #16171F;
		text-align: right;
	}
	
	.search-btn {
		margin-left: 30px;
	}
	
	.footer {
		width: 100%;
		height: 40px;
		display: flex;
		align-items: center;
		/* position: absolute; */
		/* left: 0; */
		/* bottom: 0px; */
		justify-content: center;
		height: 130px;
		background: #FFFFFF;
		box-shadow: 0px -7px 9px 0px rgba(0, 0, 0, 0.02);
	}
	
	.del-color {
		color: #D1141F;
	}
	
	.start-color {
		color: #4A92FD;
	}
	
	.yes {
		color: #69BC2E;
	}
	
	.no {
		color: #D1141F;
	}
	
	>>> .el-input__inner{
		height: 32px;
	}
	
	.search-button, .add-user {
		font-size: 14px;
		height: 32px;
		line-height: 32px;
		padding-top: 0;
		padding-bottom: 0;
	}
	
	/* 选择框 行高 */
	>>> .el-input__icon {
		line-height: 28px;
	}
	
	.min-w58 {
		min-width: 58px;
	}
	
	.min-w72 {
		min-width: 72px;
	}
	
	.min-w86 {
		min-width: 86px;
	}
	
	.min-w100 {
		min-width: 100px;
	}
	
	.min-w108 {
		min-width: 108px;
	}
	
	.min-w116 {
		min-width: 116px;
	}
	
	.w74 {
		width: 74px;
	}
</style>
